package com.es.hr.areartm;

import javax.servlet.http.HttpServletRequest;

import com.es.business.area.AreaBean;
import com.es.business.area.AreaBiz;
import com.es.business.city.CityBiz;
import com.es.business.province.ProvinceBiz;
import com.es.hr.emp.EmpInfoBean;
import com.es.util.page.PageBean;
import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.xwork.ActionSupport;

public class AreaRTMAddDoAction extends ActionSupport
implements ServletRequestAware{
	 HttpServletRequest request;

	public void setServletRequest(HttpServletRequest paramHttpServletRequest) {
		// TODO Auto-generated method stub
		this.request = paramHttpServletRequest;
	}
	
	public String execute() throws Exception{
		String result = "";
		AreaRTMBiz areaRTMBiz = new AreaRTMBiz();
		String[] areaIds = (String[]) request.getParameterMap().get("area_id");
		String empId = request.getParameter("emp_id");
		boolean res = false;
		if(areaIds != null){
			for(int i = 0; i < areaIds.length; ++i){
				AreaBean area = new AreaBiz().getAreaById(areaIds[i]);
				EmpInfoBean empBean = areaRTMBiz.getEmpById(empId);
				res = areaRTMBiz.insertAreaRTM(area, empBean, empId);
			if(res == true){
				String message = "删除成功";
				this.request.setAttribute("message", message);
			}else{
				String message = "删除失败，请重新删除";
				this.request.setAttribute("message", message);
			}
		}	
	}
			if(res == true){
				String message = "添加成功";
				this.request.setAttribute("message", message);
			}else{
				String message = "添加失败";
				this.request.setAttribute("message", message);
			}	
			
		request.setAttribute("emp_id", empId);
		request.setAttribute("curpage", "1");
		return "success";
	}
	
}
